<?php
	namespace Admin\Controller;
	use       Think\Controller;

	class GroupController extends PublicController
	{
		//查询出后台组列表
		public function index()
		{
			//实例化model类
			$group = M('auth_group');

			//执行查询方法
			$data = $group->select();

			//赋值变量
			$this->assign(data,$data);

			//输出模版
			$this->display();
		}

		//查看权限
		public function showrule()
		{
			//实例化model类
			$rule = M('auth_rule');
			$group = M('auth_group');
			//查询出所有的权限
			$data = $rule->select();
			$list = $group->find(I('get.id'));
			//dump($list);

			//赋值变量
			$this->assign(data,$data);
			$this->assign('rule',$list);
			//输出模版
			$this->display();
		}

		//跳转到添加组
		public function add()
		{
			$this->display();
		}

		//执行添加组
		public function tianjia()
		{
			//实例化model类
			$group = M('auth_group');

			//执行添加
			$res = $group->add(I('post.'));

			if($res){
				$this->success('添加成功',U('Group/index'),2);
			}else{
				$this->error('添加失败');
			}
		}


		//权限组添加权限
		public function insert()
		{
			//实例化model类
			$group = M('auth_group');
			
			//遍历出具体权限
			$data['id'] = I('post.id');
			foreach(I('post.rules') as $value){
				$rules .= $value.',';
			}
			$data['rules'] = trim($rules,',');
			
			//实行数据库修改功能
			$res = $group->save($data);
			if($res)
			{
				$this->success('修改权限成功',U('Group/index'),1);
			}else{
				$this->error('修改权限失败');
			}
		}
	}